class Room < ActiveRecord::Base
  include SecretAccessible

  has_many :clients
  has_many :messages , :dependent => :destroy
  validates_presence_of   :is_public , :secret
  validates_uniqueness_of :secret
  before_validation :assign_secret


  def self.all_empty ; self.all.select { | room | room.clients.size == 0 } ; end ;

  def clients_csv ; (self.clients.map { | client | client.name }).join ',' ; end ;


private

  def assign_secret ; self.secret = generate_secret ; end ;
end
